package com.macro.mall.demo.service.impl;

import com.macro.mall.mapper.HomeMapper;
import com.macro.mall.mapper.PmsProductMapper;
import com.macro.mall.model.*;
import com.macro.mall.demo.service.HomeService;
import com.macro.mall.mapper.PmsBrandMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HomeServiceImpl implements HomeService {

    @Autowired
    private PmsBrandMapper brandMapper;
    @Autowired
    private HomeMapper mapper;
    @Autowired
    private PmsProductMapper pmsProductMapper;

    @Override
    public HomeContenResult getHomeContent() {
        HomeContenResult homeContenResult = new HomeContenResult();
        homeContenResult.setBrandList(brandMapper.selectByExample(new PmsBrandExample()));
        return homeContenResult;
    }

    @Override
    public PmsBrand detail(Long id) {
        PmsBrand pmsBrand = brandMapper.selectByPrimaryKey(id);
        return pmsBrand;
    }

    /**
     * 获取品牌商品信息
     * @param brandId
     * @param pageSize
     * @param pageNum
     * @return
     */
    @Override
    public List<PmsProduct> list(Integer brandId, Integer pageSize, Integer pageNum) {
        return mapper.list(brandId);
    }

    @Override
    public PmsPortalProductDetail detailList(Long id) {
        //获取商品详情
        PmsProduct pmsProduct = pmsProductMapper.selectByPrimaryKey(id);
        //獲取品牌信息
        PmsBrand pmsBrand = brandMapper.selectByPrimaryKey(pmsProduct.getBrandId());
        //獲取商品屬性信息
        List<PmsProductAttribute> productAttributeList = mapper.detailList(pmsProduct.getProductAttributeCategoryId());
        PmsPortalProductDetail pmsPortalProductDetail = new PmsPortalProductDetail();
        pmsPortalProductDetail.setProduct(pmsProduct);
        pmsPortalProductDetail.setBrand(pmsBrand);
        pmsPortalProductDetail.setProductAttributeList(productAttributeList);
        return pmsPortalProductDetail;
    }



}
